public class ThreadDemo10 {
    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();

        //创建两个线程 两个线程分别对这个counter 自增3w次
        Thread t1 = new Thread(()->{
            for(int i = 0; i < 300000; i++) {
                counter.add();
            }
        });

        Thread t2 = new Thread(()->{
            for(int i = 0; i < 300000; i++) {
                counter.add();
            }
        });
        t1.start();
        t2.start();
        //等待两个线程执行完成
        t1.join();
        t2.join();

        System.out.println(counter.getCount());
    }
}
